import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import {
  DataLine, Document,
  WalletFilled, ShoppingBag, House,
  User, Monitor, Tickets, Operation, Coin, Menu,
  PieChart
} from '@element-plus/icons-vue'
import {
  ElMessage
} from 'element-plus'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/',
    name: 'home',
    redirect: "/home",
    component: () => import('../views/index.vue'),
    children: [
      {
        path: '/home',
        name: 'adminHome',
        component: () => import('../views/home.vue'),
        meta: {
          title: "首页",
          icon: House
        },
      },
      {
        path: '/menus',
        name: 'menus',
        meta: {
          title: "一级菜单",
          icon: Menu
        },
        children: [
          {
            path: '/secondaryMenu1',
            name: 'secondaryMenu1',
            component: () => import('../views/menus/secondaryMenu1.vue'),
            meta: {
              title: "二级菜单1",
              icon: Tickets
            },
          },
          {
            path: '/secondaryMenu2',
            name: 'secondaryMenu2',
            component: () => import('../views/menus/secondaryMenu2.vue'),
            meta: {
              title: "二级菜单2",
              icon: Tickets
            },
          },
        ]
      }, {
        path: '/tools',
        name: 'tools',
        meta: {
          title: "其他工具",
          icon: Menu
        },
        children: [
          {
            path: '/office',
            name: 'office',
            component: () => import('../views/tools/offic.vue'),
            meta: {
              title: "office预览",
              icon: Tickets
            },
          },
          {
            path: '/websocket',
            name: 'websocket',
            component: () => import('../views/tools/websocket.vue'),
            meta: {
              title: "websocket",
              icon: Tickets
            },
          },
        ]
      }, {
        path: '/chartsPath',
        name: 'chartsName',
        meta: {
          title: "图表展示",
          icon: PieChart
        },
        children: [
          {
            path: '/charts',
            name: 'charts',
            component: () => import('../views/charts/index.vue'),
            meta: {
              title: "图表",
              icon: PieChart
            },
          },
        ]
      },]
  },
  // {
  //   path: "/:pathMatch(.*)*",
  //   redirect: "/login",
  // },
]
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/') return next("/login")
  next()
});
// router.beforeEach((to, from, next) => {
//   let token = sessionStorage.getItem("token");
//   let userInfo = JSON.parse(sessionStorage.getItem("userInfo") || "{}");
//   if (to.path == "/login" && token) return next("/home/index");
//   if (to.path.indexOf("/admin") === 0 && userInfo.level !== 1) {
//     ElMessage.warning("普通用户无权访问 !")
//     //一定要return 不然会继续执行
//     return next("/home/index")
//   }
//   next()
// });
export default router
